import Vue from "vue"
let prototype = Vue.prototype;

export default {
    /**
     * 上传文件
     */
    upload(path) {
        return new Promise((resolve, reject) => {
            prototype.$upload({
                api: "system.uploadFile",
                path: path
            }).then(response => {
                if (response.code == 1) {
                    return resolve(response.data);
                }
                return reject(response.msg);
            });
        });
    },
    /**
     * 导航列表
     */
    navList() {
        return new Promise((resolve, reject) => {
            prototype.$request({
                api: "index.nav",
            }).then(response => {
                if (response.code == 1) {
                    let list = {
                        install: [],
                        aftermarket: [],
                        other: [],
                    };
                    response.data.lists1.forEach(item => {
                        list.install.push({
                            id: item.id,
                            cover: item.logo,
                            name: item.title,
                            page: item.types,
                        })
                    });
                    response.data.lists2.forEach(item => {
                        list.aftermarket.push({
                            id: item.id,
                            cover: item.logo,
                            name: item.title,
                            page: item.types,
                        })
                    });
                    response.data.lists3.forEach(item => {
                        list.other.push({
                            id: item.id,
                            cover: item.logo,
                            name: item.title,
                            page: item.types,
                        })
                    });
                    return resolve(list);
                }
                return reject(response.msg);
            }).catch(e => { });
        });
    },
    /**
     * 提交投诉
     */
    submitComplaint(data) {
        return new Promise((resolve, reject) => {
            prototype.$request({
                api: "system.complaint",
                data: data,
            }).then(response => {
                if (response.code == 1) {
                    return resolve(response.msg);
                }
                return reject(response.msg);
            }).catch(e => { });
        });
    },
    /**
     * 公告列表
     */
    notifyList() {
        return new Promise((resolve, reject) => {
            prototype.$request({
                api: "system.notify.list",
                data: {
                    cateid: 1,
                    page: 1,
                }
            }).then(response => {
                if (response.code == 1) {
                    let list = [];
                    response.data.forEach((item) => {
                        list.push({
                            id: item.id,
                            title: item.title,
                            content: item.message,
                        });
                    });
                    return resolve(list);
                }
                return reject(response.msg);
            }).catch(e => { throw e; });
        });
    },
    /**
     * 平台杂项数据
     */
    platformData() {
        return new Promise((resolve, reject) => {
            prototype.$request({
                api: "system.config",
            }).then(response => {
                if (response.code == 1) {
                    return resolve({
                        about: response.data.about,
                        privacy: response.data.xieyi,
                        service: response.data.zhuce,
                        serviceMobile: response.data.mobile,
                    });
                }
                return reject(response.msg);
            }).catch(e => { });
        });
    }
}
